-
Notifications
You must be signed in to change notification settings - Fork 13.7k
-Zharden-sls flag (target modifier) added to enable mitigation against straight line speculation (SLS) #136597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc |
First commit adds retpoline feature, but PR descriptions says about sls. |
Yes, first commit is in another PR #135927. |
Marking this as blocked on #135927 |
I filed an MCP for this flag: rust-lang/compiler-team#869 |
☔ The latest upstream changes (presumably #141232) made this pull request unmergeable. Please resolve the merge conflicts. |
#![feature(no_core, lang_items)] | ||
#![no_std] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use add-core-stubs, don't handwrite the minicore.
warning: target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `x86-retpoline` target modifier flag instead | ||
| | ||
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344> | ||
|
||
warning: 1 warning emitted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this possible at all?
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib | ||
//@ needs-llvm-components: x86 | ||
//@ [by_flag]compile-flags: -Zharden-sls=all | ||
//@ [by_feature]compile-flags: -Ctarget-feature=+harden-sls-ijmp,+harden-sls-ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should not be set by -Ctarget-feature
.
Some changes occurred in compiler/rustc_codegen_ssa |
Converted to "Ready for review" because retpoline PR was merged. |
Adding myself to review as part of the RfL project goal I signed up for 🙂 r? wesleywiser |
Thanks Wesley! Much appreciated. |
By the way, @azhogin, I think we should have an assembly test for this one too, even if small/trivial, to double-check LLVM is actually doing something, like in the other flags. (Another rebase is needed, given the recent renaming of the folders) Thanks! |
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Added |
tests/assembly-llvm/x86_64-sls.rs
Outdated
4 => unsafe { return std::intrinsics::unchecked_div(b, a) + 4 }, | ||
5 => unsafe { return std::intrinsics::unchecked_div(b, a) + 5 }, | ||
6 => unsafe { return std::intrinsics::unchecked_div(b, a) + 6 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume all these are here to ensure the compiler is likely to generate a jump table?
By the way, you can remove all the return
s, and it will be a bit more readable since the formatting will be redone.
tests/assembly-llvm/x86_64-sls.rs
Outdated
if a > 0 { | ||
return unsafe { std::intrinsics::unchecked_div(a, b) }; | ||
} else { | ||
return unsafe { std::intrinsics::unchecked_div(b, a) }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a > 0 { | |
return unsafe { std::intrinsics::unchecked_div(a, b) }; | |
} else { | |
return unsafe { std::intrinsics::unchecked_div(b, a) }; | |
} | |
if a > 0 { | |
unsafe { std::intrinsics::unchecked_div(a, b) } | |
} else { | |
unsafe { std::intrinsics::unchecked_div(b, a) } | |
} |
Thanks! |
…t straight line speculation (SLS)
Flag (target modifier) to mitigate against straight line speculation (SLS).
-Zharden-sls=[none|all|return|indirect-jmp]
.The flag enables the related features:
+harden-sls-ijmp,+harden-sls-ret
.The flag is tracked as a target modifier to be equal between linked crates.
Tracking issue: #116851